package com.huawei.appgallery.wishwall.ui.activity;

import android.app.ActionBar;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.LinearLayout.LayoutParams;
import android.widget.TextView;
import androidx.annotation.NonNull;
import com.huawei.android.app.ActionBarEx;
import com.huawei.appgallery.foundation.service.common.protocol.AppListFragmentProtocol;
import com.huawei.appgallery.foundation.ui.framework.activity.BaseActivity;
import com.huawei.appgallery.foundation.ui.framework.cardframe.fragment.TaskFragment;
import com.huawei.appgallery.foundation.ui.framework.uikit.ContractFragment;
import com.huawei.appgallery.foundation.ui.framework.widget.toolbar.ToolBarIcon;
import com.huawei.appgallery.serverreqkit.api.bean.ResponseBean;
import com.huawei.appgallery.serverreqkit.api.listener.IServerCallBack;
import com.huawei.appgallery.wishwall.api.IWishWallDeleteActivityProtocol;
import com.huawei.appgallery.wishwall.api.IWishWallDeleteActivityResult;
import com.huawei.appgallery.wishwall.ui.fragment.WishWallDeleteFragment.c;
import com.huawei.hmf.annotation.ActivityDefine;
import huawei.widget.HwTextView;
import java.util.ArrayList;
import java.util.List;
import o.azb;
import o.azc;
import o.cfw;
import o.cgv;
import o.cjk;
import o.cjm;
import o.BaseAlertDialog;
import o.BaseRequest;
import o.ddq;
import o.ddq.a;
import o.ddq.d;
import o.ddq.e;
import o.ddq.f;
import o.ddq.g;
import o.ddq.i;
import o.ddu;
import o.ddy;
import o.djl;
import o.doo;
import o.ContentManager;
import o.epv;
import o.ActivityUtil;
import o.evk;
import o.fjf;

@ActivityDefine(alias = "wish.wall.delete.activity", protocol = IWishWallDeleteActivityProtocol.class, result = IWishWallDeleteActivityResult.class)
public class WishWallDeleteActivity extends BaseActivity<IWishWallDeleteActivityProtocol> implements OnClickListener, c {
    private ImageView ʻॱ;
    private ToolBarIcon ʽॱ;
    private boolean ʾ;
    private djl ʿ;
    private ToolBarIcon ˈ;
    private final List<String> ˉ = new ArrayList();
    private ContractFragment ˊॱ;
    private HwTextView ˋॱ;
    private View ˏॱ;
    private IWishWallDeleteActivityProtocol ͺ;
    private Menu ॱˊ;
    private LinearLayout ॱˋ;
    private View ॱˎ;
    private LinearLayout ᐝॱ;

    private boolean ᐝ() {
        return azc.ˎ().ॱ() >= 21;
    }

    public void ˋ(@NonNull String str) {
        this.ˉ.add(str);
        ॱˊ();
    }

    public void ˎ(@NonNull String str) {
        this.ˉ.remove(str);
        ॱˊ();
    }

    private void ॱˊ() {
        ॱ(this.ˉ.size());
        if (ᐝ()) {
            ॱ(this.ॱˊ);
        } else {
            ॱ(!this.ˉ.isEmpty());
        }
    }

    public void finish() {
        fjf ˊ = fjf.ˊ(this);
        ((IWishWallDeleteActivityResult) ˊ.ॱ()).setHasDeleted(this.ʾ);
        setResult(-1, ˊ.ˊ());
        super.finish();
    }

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        ddu.ˊ.ˋ("WishWallDeleteActivity", "onCreate");
        setContentView(ddq.c.ˊ);
        cgv.ˋ(this, b.ˏ, b.ˋ);
        getWindow().getDecorView().setBackgroundColor(getResources().getColor(b.ʼ));
        this.ͺ = (IWishWallDeleteActivityProtocol) ʾ();
        if (this.ͺ != null) {
            ᐝॱ();
            ʼॱ();
            if (!ᐝ()) {
                ˏ(getResources().getConfiguration().orientation);
            }
            ॱ(this.ˉ.size());
            this.ˊॱ = ͺ();
        }
    }

    private ContractFragment ͺ() {
        ContractFragment contractFragment = (ContractFragment) cjk.ˎ().ˊ(new cjm(this.ͺ.ˎ(), new AppListFragmentProtocol()));
        if (contractFragment instanceof TaskFragment) {
            ((TaskFragment) contractFragment).ˋ(ˏॱ(), d.ʽ, "FRAGMENT_TAG");
        }
        return contractFragment;
    }

    public void setTitle(CharSequence charSequence) {
    }

    private void ᐝॱ() {
        View findViewById = findViewById(d.ॱॱ);
        azb.ˏ(findViewById);
        findViewById.findViewById(d.ˏॱ).setOnClickListener(this);
        this.ˏॱ = findViewById.findViewById(d.ˋ);
        this.ॱˋ = (LinearLayout) findViewById.findViewById(d.ˏ);
        this.ॱˋ.setOnClickListener(this);
        this.ᐝॱ = (LinearLayout) findViewById.findViewById(d.ॱ);
        this.ᐝॱ.setOnClickListener(this);
        this.ʻॱ = (ImageView) findViewById.findViewById(d.ˊ);
        this.ˋॱ = (HwTextView) findViewById.findViewById(d.ˊˋ);
        ActionBar actionBar = getActionBar();
        if (actionBar != null) {
            if (ᐝ()) {
                findViewById.setVisibility(8);
                actionBar.setTitle(getString(f.ˊॱ));
                actionBar.show();
                Drawable drawable = getResources().getDrawable(e.ˎ);
                if (drawable != null) {
                    ActionBarEx.setStartIcon(getActionBar(), true, drawable, new OnClickListener(this) {
                        final /* synthetic */ WishWallDeleteActivity ˊ;

                        {
                            this.ˊ = r1;
                        }

                        public void onClick(View view) {
                            this.ˊ.finish();
                        }
                    });
                }
                actionBar.setDisplayHomeAsUpEnabled(false);
                return;
            }
            actionBar.hide();
        }
    }

    private void ʼॱ() {
        int ˊ = epv.ˊ(this, 2);
        this.ॱˎ = findViewById(d.ˊᐝ);
        this.ˈ = (ToolBarIcon) findViewById(d.ˋᐝ);
        this.ˈ.setOnClickListener(this);
        LayoutParams layoutParams = (LayoutParams) this.ˈ.getLayoutParams();
        layoutParams.gravity = 17;
        layoutParams.width = ˊ;
        this.ˈ.setLayoutParams(layoutParams);
        this.ˈ.ˋ().setText(f.ᐝ);
        this.ʽॱ = (ToolBarIcon) findViewById(d.ˋˋ);
        this.ʽॱ.setOnClickListener(this);
        layoutParams = (LayoutParams) this.ʽॱ.getLayoutParams();
        layoutParams.gravity = 17;
        layoutParams.width = ˊ;
        this.ʽॱ.setLayoutParams(layoutParams);
        this.ʽॱ.ˋ().setText(f.ʼ);
        Drawable drawable = getDrawable(e.ˋ);
        ˊ = getResources().getDimensionPixelOffset(a.ॱ);
        drawable.setBounds(0, 0, ˊ, ˊ);
        this.ʽॱ.ˋ().setCompoundDrawables(null, drawable, null, null);
        ॱ(false);
    }

    public boolean onCreateOptionsMenu(Menu menu) {
        super.onCreateOptionsMenu(menu);
        if (ᐝ()) {
            ॱ(menu);
        }
        return true;
    }

    public boolean onOptionsItemSelected(MenuItem menuItem) {
        if (menuItem.getItemId() == 16908332) {
            finish();
            return true;
        } else if (menuItem.getItemId() == d.ᐝॱ) {
            if (this.ˈ == null) {
                return true;
            }
            this.ˈ.performClick();
            return true;
        } else if (menuItem.getItemId() != d.ॱˋ) {
            return super.onOptionsItemSelected(menuItem);
        } else {
            if (this.ʽॱ == null) {
                return true;
            }
            this.ʽॱ.performClick();
            return true;
        }
    }

    public void onConfigurationChanged(Configuration configuration) {
        super.onConfigurationChanged(configuration);
        ॱ(this.ˉ.size());
        invalidateOptionsMenu();
        if (configuration == null) {
            return;
        }
        if (ᐝ()) {
            ॱ(this.ॱˊ);
        } else {
            ˏ(configuration.orientation);
        }
    }

    private void ˏ(int i) {
        if (i == 2) {
            this.ॱˎ.setVisibility(8);
            this.ˏॱ.setVisibility(0);
            return;
        }
        this.ॱˎ.setVisibility(0);
        this.ˏॱ.setVisibility(8);
    }

    public void onClick(View view) {
        int id = view.getId();
        if (id == d.ˏॱ) {
            finish();
        } else if (id == d.ˋᐝ || id == d.ˏ) {
            ˊˊ();
        } else if (id == d.ˋˋ || id == d.ॱ) {
            ˉ();
        }
    }

    private void ॱ(Menu menu) {
        if (this.ॱˎ != null) {
            this.ॱˎ.setVisibility(8);
        }
        if (this.ˏॱ != null) {
            this.ˏॱ.setVisibility(8);
        }
        if (menu != null) {
            menu.clear();
            getMenuInflater().inflate(i.ˏ, menu);
            MenuItem findItem = menu.findItem(d.ᐝॱ);
            if (this.ˉ.isEmpty()) {
                CharSequence spannableString = new SpannableString(findItem.getTitle());
                spannableString.setSpan(new ForegroundColorSpan(getResources().getColor(b.ॱॱ)), 0, spannableString.length(), 0);
                findItem.setTitle(spannableString);
                findItem.setEnabled(false);
            } else {
                findItem.setIcon(e.ॱ);
                findItem.setTitle(f.ᐝ);
            }
            this.ॱˊ = menu;
        }
    }

    private void ॱ(boolean z) {
        this.ˈ.setEnabled(z);
        this.ॱˋ.setEnabled(z);
        this.ˈ.ˋ().setTextColor(getResources().getColor(z ? b.ˎ : b.ॱॱ));
        Drawable drawable = getDrawable(z ? e.ॱ : e.ʼ);
        int dimensionPixelOffset = getResources().getDimensionPixelOffset(a.ॱ);
        drawable.setBounds(0, 0, dimensionPixelOffset, dimensionPixelOffset);
        this.ˈ.ˋ().setCompoundDrawables(null, drawable, null, null);
        this.ʻॱ.setImageDrawable(drawable);
    }

    private void ˊˊ() {
        if (this.ˉ.isEmpty()) {
            ddu.ˊ.ˋ("WishWallDeleteActivity", "showDeleteDialog, no selected wish");
            return;
        }
        final BaseAlertDialog ˋ = BaseAlertDialog.ˋ(this, null, getResources().getQuantityString(g.ˊ, this.ˉ.size(), new Object[]{Integer.valueOf(this.ˉ.size())}));
        ˋ.ॱ();
        ˋ.ॱ(BaseAlertDialog.a.CONFIRM, getString(f.ॱॱ));
        ˋ.ˊ(new OnClickListener(this) {
            final /* synthetic */ WishWallDeleteActivity ˊ;

            public void onClick(View view) {
                ˋ.ˏ();
                this.ˊ.ˎ(false, this.ˊ.ˉ);
            }
        });
    }

    private void ˉ() {
        final BaseAlertDialog ˋ = BaseAlertDialog.ˋ(this, null, getString(f.ʽ));
        ˋ.ॱ();
        ˋ.ॱ(BaseAlertDialog.a.CONFIRM, getString(f.ʼ));
        ˋ.ˊ(new OnClickListener(this) {
            final /* synthetic */ WishWallDeleteActivity ॱ;

            public void onClick(View view) {
                ˋ.ˏ();
                this.ॱ.ˎ(true, null);
            }
        });
    }

    private void ˎ(boolean z, List<String> list) {
        if (doo.ˊ((Context) this)) {
            this.ʿ = new djl(this);
            this.ʿ.setCanceledOnTouchOutside(false);
            this.ʿ.ˋ(getString(f.ͺ));
            this.ʿ.show();
            cfw.ˎ(new ddy(z, list), new IServerCallBack(this) {
                final /* synthetic */ WishWallDeleteActivity ˏ;

                {
                    this.ˏ = r1;
                }

                public void prePostResult(BaseRequest o_cvu, ResponseBean responseBean) {
                }

                public void notifyResult(BaseRequest o_cvu, ResponseBean responseBean) {
                    if (ActivityUtil.isAcitivtyNotValid(this.ˏ)) {
                        ddu.ˊ.ˋ("WishWallDeleteActivity", "activity destroyed, ignore response");
                        return;
                    }
                    this.ˏ.ʿ.dismiss();
                    if (responseBean.getResponseCode() == 0 && responseBean.getRtnCode_() == 0) {
                        if (!this.ˏ.ʾ) {
                            this.ˏ.ʾ = true;
                        }
                        this.ˏ.finish();
                        return;
                    }
                    ddu.ˊ.ˋ("WishWallDeleteActivity", "delete failed!!!");
                    evk.ॱ(ContentManager.getInstant().getContext().getString(f.ʻ), 0).ˋ();
                }
            });
            return;
        }
        evk.ॱ(ContentManager.getInstant().getContext().getString(f.ˎ), 0).ˋ();
    }

    private void ॱ(int i) {
        ˋ(i, getActionBar(), getApplicationContext(), this.ˋॱ);
    }

    private void ˋ(int i, ActionBar actionBar, Context context, @NonNull TextView textView) {
        if (ᐝ()) {
            if (actionBar == null) {
                return;
            }
            if (i > 0) {
                actionBar.setTitle(context.getResources().getQuantityString(g.ˏ, i, new Object[]{Integer.valueOf(i)}));
                return;
            }
            actionBar.setTitle(context.getString(f.ˊॱ));
        } else if (i > 0) {
            textView.setText(context.getResources().getQuantityString(g.ˏ, i, new Object[]{Integer.valueOf(i)}));
        } else {
            textView.setText(context.getString(f.ˊॱ));
        }
    }
}
